home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9147 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  912 b 

  1. Path: rap.SanDiegoCA.ATTGIS.COM!news
  2. From: borisb@sd.znet.com (Boris Burtin)
  3. Newsgroups: comp.lang.c++,rb.technical
  4. Subject: Can copy constructor and operator= share code?
  5. Date: Wed, 28 Feb 1996 22:19:28 GMT
  6. Organization: Lunapark Studios
  7. Message-ID: <4h2kcn$40d@rap.SanDiegoCA.ATTGIS.COM>
  8. NNTP-Posting-Host: borisbpc.sandiegoca.attgis.com
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. I have noticed that a copy constructor and operator= perform pretty
  12. much the same function.  The code I wrote for my class simply copies
  13. each member variable from one class to the other.
  14.  
  15. Is there a way for the one of the two functions to call the other, to
  16. avoid duplicate code?  I have tried calling the copy constructor from
  17. operator=, but nothing happens.  I've gotten around this problem by
  18. creating a private Copy() function, which is called by both the copy
  19. constructor and operator=.  Is there another way?
  20.  
  21. Thanks,
  22.  
  23. Boris
  24.  
  25.  
  26.